//
//  CancelOrderVm.swift
//  Pods
//
//  Created by eme on 2017/3/28.
//
//

import RxSwift
import SwiftyJSON
import NetWorkCore
import ModelProtocol

class CancelOrderVm{
    
    let cancelOrder = PublishSubject<String>()
    
    let backDate = PublishSubject<Bool>()
    
    let disposeBag = DisposeBag()
    
    let error = PublishSubject<MikerError>()
    
    let refreshing = Variable(false)
    
    
    init (){
        
        let request = cancelOrder.map{payid in
            
            return MineApi.cancelOrder(payid: payid)
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForRegJson().shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            
            switch result{
                
            case .success(_):
                
                self.backDate.onNext(true)
                
            case.failure(let error):
                
                self.error.onNext(error)
                
            }
            
        }).addDisposableTo(disposeBag)
        
        
        //        Observable
        //            .of(
        //                request.map { _ in true },
        //                response.map { _ in false },
        //                error.map { _ in false }
        //            )
        //            .merge()
        //            .bindTo(refreshing)
        //            .addDisposableTo(disposeBag)
    }
    
}
